package com.maple.exclusivesport;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.maple.exclusivesport.adapters.ContactInfo;

import org.greenrobot.eventbus.EventBus;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by maple on 2019/8/20 14:39
 * E-Mail Address：740917401@qq.com
 */
public class PersonInfoDialog extends Dialog {


    @Bind(R.id.weight)
    EditText weight;
    @Bind(R.id.journal)
    EditText journal;

    Context context;

    public PersonInfoDialog(Context context) {
        super(context, R.style.CustomDialog);
        this.context = context;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View view = View.inflate(getContext(), R.layout.dialog_person_info, null);
        ButterKnife.bind(this, view);
        setContentView(view);
    }
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private String getTime() {
        long times = System.currentTimeMillis();
        Date date = new Date(times);
        return format.format(date);
    }

    @OnClick(R.id.send)
    public void onViewClicked() {
        String weightString = weight.getText().toString();
        String journalString = journal.getText().toString();
        if(TextUtils.isEmpty(journalString)||TextUtils.isEmpty(weightString)){
            Toast.makeText(getContext(),"请不要留空哦",Toast.LENGTH_SHORT).show();
        }else {
        DataBaseOpenHelper.getInstance(getContext()).insertContactInfo(new ContactInfo(getTime(), weightString, journalString, Constants.filePath));
        TTSUtils.getSingleton(context).tts.speak("恭喜你，打卡成功，掉肉10斤", TextToSpeech.QUEUE_FLUSH, null);
        dismiss();
        ((Activity) context).finish();
        EventBus.getDefault().post(new SendEvent());
        }
    }
}
